# Change this file when releasing a new version.

# Version numbers.
set(CLEMENTINE_VERSION_MAJOR 0)
set(CLEMENTINE_VERSION_MINOR 7)
set(CLEMENTINE_VERSION_PATCH 1)
#set(CLEMENTINE_VERSION_PRERELEASE rc1)

# This should be set to OFF in a tag
set(INCLUDE_GIT_REVISION ON)

# The format for version numbers is:
# Display: $major.$minor[.$patch] [$prerelease] [r$svn]
# Deb:     $major.$minor[.$patch][~$prerelease][.r$svn]
# Rpm:     $major.$minor[.$patch][$prerelease][.r$svn]
# And the rpm version is used for mac and windows


set(CLEMENTINE_VERSION_DISPLAY "${CLEMENTINE_VERSION_MAJOR}.${CLEMENTINE_VERSION_MINOR}")
set(CLEMENTINE_VERSION_DEB "${CLEMENTINE_VERSION_MAJOR}.${CLEMENTINE_VERSION_MINOR}")
set(CLEMENTINE_VERSION_RPM "${CLEMENTINE_VERSION_MAJOR}.${CLEMENTINE_VERSION_MINOR}")

# Add patch
if(CLEMENTINE_VERSION_PATCH)
  set(CLEMENTINE_VERSION_DISPLAY "${CLEMENTINE_VERSION_DISPLAY}.${CLEMENTINE_VERSION_PATCH}")
  set(CLEMENTINE_VERSION_DEB "${CLEMENTINE_VERSION_DEB}.${CLEMENTINE_VERSION_PATCH}")
  set(CLEMENTINE_VERSION_RPM "${CLEMENTINE_VERSION_RPM}.${CLEMENTINE_VERSION_PATCH}")
endif(CLEMENTINE_VERSION_PATCH)

# Add prerelease
if(CLEMENTINE_VERSION_PRERELEASE)
  set(CLEMENTINE_VERSION_DISPLAY "${CLEMENTINE_VERSION_DISPLAY} ${CLEMENTINE_VERSION_PRERELEASE}")
  set(CLEMENTINE_VERSION_DEB "${CLEMENTINE_VERSION_DEB}~${CLEMENTINE_VERSION_PRERELEASE}")
  set(CLEMENTINE_VERSION_RPM "${CLEMENTINE_VERSION_RPM}${CLEMENTINE_VERSION_PRERELEASE}")
endif(CLEMENTINE_VERSION_PRERELEASE)

# Add git revision
if(FORCE_GIT_REVISION)
  set(GIT_REVISION ${FORCE_GIT_REVISION})
else(FORCE_GIT_REVISION)
  find_program(GIT_EXECUTABLE git)

  if(NOT GIT_EXECUTABLE-NOTFOUND)
    execute_process(COMMAND ${GIT_EXECUTABLE} describe
        RESULT_VARIABLE GIT_INFO_RESULT
        OUTPUT_VARIABLE GIT_REV
        ERROR_QUIET
        OUTPUT_STRIP_TRAILING_WHITESPACE)
    if(${GIT_INFO_RESULT} EQUAL 0)
      set(GIT_REVISION ${GIT_REV})
    endif(${GIT_INFO_RESULT} EQUAL 0)
  endif(NOT GIT_EXECUTABLE-NOTFOUND)
endif(FORCE_GIT_REVISION)

if(INCLUDE_GIT_REVISION AND GIT_REVISION)
  set(CLEMENTINE_VERSION_DISPLAY "${GIT_REVISION}")
  set(CLEMENTINE_VERSION_DEB "${GIT_REVISION}")

  # RPM doesn't like dashes in version numbers
  string(REPLACE "-" "." CLEMENTINE_VERSION_RPM "${GIT_REVISION}")
endif(INCLUDE_GIT_REVISION AND GIT_REVISION)
